<html>
<head><meta charset="utf-8"><title>When did vec.push(vec.len()) start working? · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/When.20did.20vec.2Epush(vec.2Elen()).20start.20working.3F.html">When did vec.push(vec.len()) start working?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="243989084"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/When%20did%20vec.push%28vec.len%28%29%29%20start%20working%3F/near/243989084" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Teddy Katz <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/When.20did.20vec.2Epush(vec.2Elen()).20start.20working.3F.html#243989084">(Jun 26 2021 at 02:05)</a>:</h4>
<p>I remember that in older versions of rust, <code>vec.push(vec.len())</code> would (somewhat infamously) fail with a borrow-checking error. However, it seems to work now. Do we know what change specifically caused it to start working? <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=fa71b591155a5d37451aed78d197acee">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=fa71b591155a5d37451aed78d197acee</a></p>



<a name="243989146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/When%20did%20vec.push%28vec.len%28%29%29%20start%20working%3F/near/243989146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/When.20did.20vec.2Epush(vec.2Elen()).20start.20working.3F.html#243989146">(Jun 26 2021 at 02:06)</a>:</h4>
<p>I don't know when it changed, but it's called "multi-stage borrows" I think</p>



<a name="243989152"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/When%20did%20vec.push%28vec.len%28%29%29%20start%20working%3F/near/243989152" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/When.20did.20vec.2Epush(vec.2Elen()).20start.20working.3F.html#243989152">(Jun 26 2021 at 02:06)</a>:</h4>
<p>you could use <code>bisect-rustc</code> to see if you're really curious</p>



<a name="243989490"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/When%20did%20vec.push%28vec.len%28%29%29%20start%20working%3F/near/243989490" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/When.20did.20vec.2Epush(vec.2Elen()).20start.20working.3F.html#243989490">(Jun 26 2021 at 02:14)</a>:</h4>
<p>This was enabled by non-lexical lifetimes (NLL), which has an epically long RFC: <a href="https://github.com/rust-lang/rfcs/blob/master/text/2094-nll.md">https://github.com/rust-lang/rfcs/blob/master/text/2094-nll.md</a></p>



<a name="243989621"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/When%20did%20vec.push%28vec.len%28%29%29%20start%20working%3F/near/243989621" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Yu [they/she] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/When.20did.20vec.2Epush(vec.2Elen()).20start.20working.3F.html#243989621">(Jun 26 2021 at 02:18)</a>:</h4>
<p>so is NLL still feature-gated? or have parts of it made it into nightly or stable? i'm having a hard time discovering details</p>



<a name="243989624"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/When%20did%20vec.push%28vec.len%28%29%29%20start%20working%3F/near/243989624" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/When.20did.20vec.2Epush(vec.2Elen()).20start.20working.3F.html#243989624">(Jun 26 2021 at 02:18)</a>:</h4>
<p>I'm amused, looking at it again, it mentions that disjoint closure captures won't be fixed by NLL. And here were are in the next edition will get that fixed.</p>



<a name="243989720"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/When%20did%20vec.push%28vec.len%28%29%29%20start%20working%3F/near/243989720" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/When.20did.20vec.2Epush(vec.2Elen()).20start.20working.3F.html#243989720">(Jun 26 2021 at 02:21)</a>:</h4>
<p>There are multiple steps on the NLL journey.  I believe both 2015 and 2018 run in what is called "migrate" mode, though I'm not really sure what the distinction is between that and "full" nll mode.</p>



<a name="243990930"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/When%20did%20vec.push%28vec.len%28%29%29%20start%20working%3F/near/243990930" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/When.20did.20vec.2Epush(vec.2Elen()).20start.20working.3F.html#243990930">(Jun 26 2021 at 02:54)</a>:</h4>
<p>my memory says that even with nll it didn't work initially.</p>



<a name="243992634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/When%20did%20vec.push%28vec.len%28%29%29%20start%20working%3F/near/243992634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/When.20did.20vec.2Epush(vec.2Elen()).20start.20working.3F.html#243992634">(Jun 26 2021 at 03:42)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/122651-general/topic/When.20did.20vec.2Epush.28vec.2Elen.28.29.29.20start.20working.3F/near/243989146">said</a>:</p>
<blockquote>
<p>I don't know when it changed, but it's called "multi-stage borrows" I think</p>
</blockquote>
<p>I think it was "two-phase borrows". <a href="https://rustc-dev-guide.rust-lang.org/borrow_check/two_phase_borrows.html">https://rustc-dev-guide.rust-lang.org/borrow_check/two_phase_borrows.html</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>